using Gateway.Common.Enums;
using Gateway.Common.Extensions;
using Gateway.Domain.EFCore.Configuration;
using Gateway.Domain.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Gateway.Domain.Configuration;

public class SystemSmsConfiguration : EntityConfiguration<SystemSms>
{
    public override void Configure(EntityTypeBuilder<SystemSms> builder)
    {
        builder.ToTable(t => t.HasComment("系统短信配置表"));
        base.Configure(builder);
        builder.Property(x => x.Status).IsRequired().IsFixedLength().HasComment("短信状态 Y 开 N 关")
            .HasConversion(x => x.Value,
                p => BooleanStatusEnum.FromValue(p));
        builder.Property(x => x.AppKey).HasMaxLength(500).HasComment("短信key");
        builder.Property(x => x.SecretKey).HasMaxLength(500).HasComment("短信 secret ");
        builder.Property(x => x.SystemSettingId).HasMaxLength(36).HasComment("系统配置标识");
        builder.HasOne(x => x.SystemSetting).WithOne(p => p.Sms)
            .HasForeignKey<SystemSms>(x => x.SystemSettingId)
            .OnDelete(DeleteBehavior.Cascade);
    }
}